﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using T2_garage.Component;

namespace T2_garage
{
    public partial class Form1 : Form
    {
        public FileIO file;

        public Form1()
        {
            InitializeComponent();
            file = new FileIO();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            


        }

        private void btnParkeer_Click(object sender, EventArgs e)
        {
            int index = file.writeValue();
            if (index != -1)
            {
                tbAuthCodePark.Text = file.authCodes[index].ToString();
                int place = index + 1;
                lblPlacePark.Text = place.ToString();
            }
        }

        private void btnArrayDisplay_Click(object sender, EventArgs e)
        {
            MessageBox.Show(file.authCodes[0] + "\n" + file.authCodes[1] + "\n" + file.authCodes[2] + "\n" + file.authCodes[3] + "\n" + file.authCodes[4] + "\n" + file.authCodes[5]);
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            file.writeFile();
            this.Close();
            Application.Exit();
        }

        private void btnFetch_Click(object sender, EventArgs e)
        {
            try
            {
                int authCode = Int32.Parse(tbAuthCodeFetch.Text);
                if (file.deleteValue(authCode))
                {
                    MessageBox.Show("Uw auto wordt opgehaald");
                }
                else
                {
                    MessageBox.Show("Ongeldige authenticatie code.");
                }
            }
            catch (FormatException x)
            {
                MessageBox.Show("Voer astublieft een geldige authenticatie code in.");
            }
        }
    }
}
